﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Collections;
using System.Data;

namespace DAO
{
    public class ThamSoDAO
    {
        public static ThamSoDTO LayThongTinThamSo()
        {
            ThamSoDTO dv = new ThamSoDTO();
            string sql = "Select * From ThamSo";
            DataTable dt = DataAccess.ExcuQuery(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                dv.SoLuongNhaptoiThieu = Convert.ToInt32(dt.Rows[0]["SoLuongNhaptoiThieu"]);
                dv.SoLuongTonQuiDinh = Convert.ToInt32(dt.Rows[0]["SoLuongTonToiThieuKhiNhap"]);
                dv.SoLuongTonQuiDinhBan = Convert.ToInt32(dt.Rows[0]["SoLuongTonToiThieuSauBan"]);
                dv.TienNoQuiDinh = float.Parse(dt.Rows[0]["TienNoToiDa"].ToString());
                dv.SuDungQuiDinh4 = Convert.ToInt32(dt.Rows[0]["ApDungQuyDinhThuTien"].ToString());
            }
            return dv;
        }

        public static int CapNhat(ThamSoDTO ts)
        {
            string sql;
            sql = "UPDATE THAMSO SET SoLuongNhaptoiThieu=" + ts.SoLuongNhaptoiThieu + ",SoLuongTonQuiDinh=" + ts.SoLuongTonQuiDinh + ",TienNoQuiDinh=" + ts.TienNoQuiDinh + ",SoLuongTonQuiDinhBan=" + ts.SoLuongTonQuiDinhBan + ",SuDungQuyDinh4='" + ts.SuDungQuiDinh4 + "'";
            int kq = DataAccess.ExcuNonQuery(sql);
            return kq;
        }

    }
}
